/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package cn.icanci.order.entity;

import cn.icanci.basic.commonutils.R;
import cn.icanci.order.module.OrderInfo;
import cn.icanci.order.repository.OrderInfoRepository;
import lombok.Data;

import java.util.List;

/**
 * @author icanci
 * @date Created in 2021/05/04 15:49
 * @version 1.0
 */
@SuppressWarnings("all")
@Data
public class OrderEntity extends OrderInfo {
    /**
     * 仓储
     */
    private OrderInfoRepository orderInfoRepository;

    public OrderEntity(OrderInfoRepository orderInfoRepository) {
        this.orderInfoRepository = orderInfoRepository;
    }

    public int saveOneOrder() {
        return orderInfoRepository.saveOneOrder(this);
    }

    public List<OrderInfo> queryManyRowByUserPhone(String phoneNumber) {
        return orderInfoRepository.queryManyRowByUserPhone(phoneNumber);
    }

    public int updateOneOrder() {
        return orderInfoRepository.updateOneOrder(this);
    }

    public R queryOneBuyed() {
        OrderInfo orderInfo = orderInfoRepository.queryOneRowByTicketNumber(this.getFlightNumber(), this.getUserId());
        if (null == orderInfo) {
            return R.ok().message("用户尚未下单");
        }
        return R.error().message("您已经下单次机票，请勿重复下单");
    }
}
